package com.alit.ibot.robot.projectvariable;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * 初始化工程变量
 *
 * @author litong
 * @version 1.0
 * @date 2019年2月11日_下午12:37:56
 */
@Slf4j
public class ProjectVariableInit {

  /**
   * 初始化工程变量, 初始化值不需要保存到文件,初始化完成后会自动保存
   *
   * @param parameters
   */
  public static void initValue() {
    initWchat();
    initIbotRobot();
    initKod();
  }

  private static void initKod() {
    PVU.add(PVK.kodURLInternet, "知识库地址外网", "http://kod.online.uairobot.com", false, false);
    PVU.add(PVK.kodURLInternal, "kod地址内网", "http://127.0.0.1:1027", false, false);
    PVU.add(PVK.kodUserName, "kod用户名", "admin", false, false);
    PVU.add(PVK.kodApiLoginToken, "kod.api.login.token", "litong", false, false);
    PVU.add(PVK.kodUploadDir, "kod文件上传目录", "/var/www/html/data/User/admin/home/bjhg", false, false);
  }

  private static void initWchat() {
    PVU.add(PVK.wechatAppId, "appid", "wxbacf3833f9c0c65c", false, false);
    PVU.add(PVK.wechatSecret, "secret", "973d8c40f4aeee65b7d4d58917c69b73", false, false);
    PVU.add(PVK.wechatToken, "token", "hgrobot2016", false, false);
    PVU.add(PVK.wechatEncodingAESKey, "encodingAESKey", "CX1er6UunGTxWEVoXu9UEngyffoCpWjDJ3GptFfmvKO", false, false);
    PVU.add(PVK.wechatDefaultReply, "默认回复", "", false, false);
    setDownloadDir(); // 设置图片下载和附件存储文件夹
  }

  private static void setDownloadDir() {
    File directory = new File("download_dir");
    try {
      FileUtils.forceMkdir(directory); // 创建文件夹
      log.info("创建文件夹:" + directory.getAbsolutePath());
    } catch (IOException e) {
      e.printStackTrace();
    }
    ProjectVariableUtil.add(PVK.projectDownloadDir, "下载其系统文件存放路径", directory.getAbsolutePath() + File.separator, true,
        true);
  }

  private static void initIbotRobot() {
    String robotURLInternet = "http://ibotcluster.online.uairobot.com/robot/app/bjhg";
    String robotURLInternal = "http://127.0.0.1/robot/app/bjhg";
    PVU.add(PVK.robotURLInternet, "知识库地址外网", robotURLInternet, false, false);
    PVU.add(PVK.robotURLInternal, "知识库地址内网", robotURLInternal, false, false);
    PVU.add(PVK.robotNameCN, "机器人中文名字", "U佳", false, false);
    PVU.add(PVK.robotNameEN, "机器人英文名字", "uairboot", false, false);
  }

}
